{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "from keras.preprocessing import image\n",
    "from keras.models import load_model\n",
    "import matplotlib.pyplot as plt\n",
    "from instance_normalization import InstanceNormalization\n",
    "from my_upsampling_2d import MyUpSampling2D\n",
    "from FgSegNet_v2_module import loss, acc, loss2, acc2\n",
    "\n",
    "def load_image(path):\n",
    "    x = image.load_img(path)\n",
    "    x = image.img_to_array(x)\n",
    "    x = np.expand_dims(x, axis=0)\n",
    "    return x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1/1 [==============================] - 2s 2s/step\n",
      "(1, 240, 320, 1)\n",
      "(240, 320)\n"
     ]
    }
   ],
   "source": [
    "# Segment on a single CPU for this test\n",
    "# Want to speed up training or testing?\n",
    "# Read my blog post at https://towardsdatascience.com/a-comprehensive-guide-on-how-to-fine-tune-deep-neural-networks-using-keras-on-google-colab-free-daaaa0aced8f\n",
    "\n",
    "# a sample FgSegNet_v2 model can be downloaded at https://drive.google.com/open?id=1Rr-NCcYdNKtDfQWGYWhRVDDvCLnXASLz\n",
    "# a sample test frame can be downloaded at https://drive.google.com/open?id=1pONZTp604CFg5MSqTknj875hYAYTtifE\n",
    "image_path = 'in001530.jpg'\n",
    "model_path = 'mdl_highway_fgsegnet_v2.h5'\n",
    "\n",
    "x = load_image(image_path) # load a test frame\n",
    "model = load_model(model_path, custom_objects={'MyUpSampling2D': MyUpSampling2D, 'InstanceNormalization': InstanceNormalization, 'loss':loss, 'acc':acc, 'loss2':loss2, 'acc2':acc2}) #load the trained model\n",
    "probs = model.predict(x, batch_size=1, verbose=1)\n",
    "print(probs.shape) # (1, 240,320,1)\n",
    "probs = probs.reshape([probs.shape[1], probs.shape[2]])\n",
    "print(probs.shape) # (240,320)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAU0AAAEICAYAAADbZaYbAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAHR5JREFUeJzt3Xt0HNV9B/Dvb1f71Gv1sCzLEpLB\noRaxibFxDbhusQs2puE0EDh10gZCCxSSkpSS1HGhDQlJ3AYCIQGSnLxj4tAklIChtDxq1yUEKK05\nBVc0BmxHRpawLOtpvXb39o+5MqNFjx1pV3dn5vs5Z8/RamZnfjs78917Z2ZnRCkFIiLKTsB0AURE\nbsLQJCJygKFJROQAQ5OIyAGGJhGRAwxNIiIHGJo+IyLfFJG/NV3HTInIQRG5IMtxlYgsnuF81ojI\nfhHpF5EPzGQasyEit4nIA3Mwnya9nIpm8NrzReTwFMN/ICJf0H+vFZH/m02thcI3oSkivyMiz4lI\nj4h0icgvRWSV6bqcsK+EWY7/URF51v4/pdT1Sqnbc1+d53wewL1KqRKl1C/yOaPpwscLlFL/oZT6\nLdN15ILjbxc3EpEyAI8BuAHATwGEAawFMGyyLipojQD2zeSFIlKklErmuJ6CmZ/vKaU8/wBwNoDu\nacb5UwAtAI4D+FcAjbZhGwD8H4AeAPcD+HcA1+hhHwXwSwB3A+gG8CaA8/T/WwG8DeAq27QiAO4E\n8BsAHQC+CSCmh50P4DCAm/XrjgC4Wg+7DsAogBEA/QB26v9/BsAbAPoA/C+AS/X/mwEMAUjp8bv1\n/38A4Au2eq4F8DqALgCPAqizDVMArgewXy+X+wDIJMvvNgA/A/CAruUVAKcD2KrfSyuADbbxr9bL\nu08vsz+3DauG9SXXrev6DwABPewggAv030sAHACweZKaFIBP6Ol3ArhjbDpTfeZ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Vu2DM8//7zpMoh8pyD2aT7wwANq/fr1iEajqKio4P66\nLOzfvx+nn3666TKIPMNV+zRTqRTC4TBisRgDM0uxWMx0CUS+VBDd85qaGpSUlCAUCpkuxTXi8bjp\nEoh8qSBCs6GhAeFwmEeEHeAXDJEZBZFStbW1DEyHJrqNKxHlX0EkFX9XTkRuURCh6deLChOR+xRE\naLKr6Vw6nTZdApEvFURocn+mc366fTFRIWFauRRDk8gMhqZLHTp0yHQJRL7E0HSpX//616ZLIPIl\nhqZL7d+/33QJRL7E0HSpN954w3QJRL7E0HSp48ePmy6ByJcYmi515MgR0yUQ+RJD06V6e3tNl0Dk\nSwxNl+KtLojMYGi6VH9/v+kSiHyJoelSw8PDpksg8qWCuEcQgIIowk2CwSAv2kGUQ666RxA5Mzg4\nyMAkMoSh6TKDg4Nobm42XQaRbzE0XSSdTuOyyy7jxTqIDCqIG6sppXjr3mkMDg5iz5492L17t+lS\niHytUA4EERG5ArvnREQOMDSJiBxgaBIROcDQJCJygKFJROQAQ5OIyAGGJhGRAwxNIiIHGJpERA4w\nNImIHGBoEhE5wNAkInKAoUlE5ABDk4jIAYYmEZEDDE0iIgcYmkREDjA0iYgcYGgSETnA0CQicoCh\nSUTkAEOTiMgBhiYRkQP/D6F3z1B2+2+JAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x181e6fbe48>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# plot the first segmentation mask\n",
    "\n",
    "plt.subplot(1, 1, 1)\n",
    "plt.rcParams['figure.figsize'] = (5.0, 5.0)\n",
    "plt.rcParams['image.cmap'] = 'gray'\n",
    "\n",
    "plt.imshow(probs)\n",
    "\n",
    "plt.title('Segmentation mask before thresholding')\n",
    "plt.axis('off')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAUIAAA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JiHEPQZpKhlBSeoZQUnqGUFJ6hlBSeoZQUnqGUFJ6hlBSeoZQUnqGUFJ6hrAn/LdKpNExhD1g\nBKXRMoQTzghKoxf+j5MkZecRoaT0DKGk9AyhpPQMoaT0DKGk9AyhpPQMoaT0DKGk9AyhpPQMoaT0\nDKGk9AyhpPQMoaT0DKGk9AyhpPQMoaT0DKGk9AyhpPQMoaT0DKGk9AyhpPQMoaT0DKGk9P4fJbjx\nvmo8xkAAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x181e11b4a8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Thresholding (one can specify any threshold values)\n",
    "threshold = 0.8\n",
    "probs[probs<threshold] = 0.\n",
    "probs[probs>=threshold] = 1.\n",
    "\n",
    "plt.subplot(1, 1, 1)\n",
    "plt.rcParams['figure.figsize'] = (5.0, 5.0)\n",
    "plt.rcParams['image.cmap'] = 'gray'\n",
    "\n",
    "plt.imshow(probs)\n",
    "\n",
    "plt.title('Segmentation mask after thresholding')\n",
    "plt.axis('off')\n",
    "plt.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
